$(function () {
	function infoTips(tips, cls){		
		$( "#dialog-confirm" ).html(tips).removeClass('hide').dialog({
			resizable: false,
			modal: true,
			title: "提示",
			title_html: true,
			buttons: [
				{
					html: "<i class='icon-trash'></i>&nbsp; 关闭",
					"class" : "btn btn-xs",
					click: function() {
						$( this ).dialog( "close" );
					}
				}
				,
				{
					html: "<i class='icon-remove'></i>&nbsp; 确定",
					"class" : "btn btn-xs "+cls,
					click: function() {
						$( this ).dialog( "close" );
					}
				}
			]
		});
	}
	$.validator.setDefaults({
		submitHandler: function() {
		    $.post('/UserInfo/editPassword.do', $('.passwdForm').serialize(), function(data){
				if(!data){
					RM.tips("对不起，服务器繁忙，请稍候重试", "btn-danger");
				}else{
					RM.tips("修改成功", "btn-primary");
				}
			});
			return false;
		}
	});
	$('.passwdForm').validate({
		rules: {
		  password: {
			required: true,
			minlength: 5
		  },
		  newpassword: {
			required: true,
			minlength: 5
		  },
		  repassword: {
			required: true,
			minlength: 5,
	        equalTo: "#newpassword"
		  }
		},
		messages: {
			password: {
				required: "请输入密码",
				minlength: "密码长度不能小于 5 个字母"
			},
			newpassword: {
				required: "请输入密码",
				minlength: "密码长度不能小于 5 个字母"
			},
			repassword: {
				required: "请输入密码",
				minlength: "密码长度不能小于 5 个字母",
		        equalTo: "两次密码输入不一致"
			}
		}
	})
});